package com.youyi.yyviewsdklibrary.Dialog.core;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupPosition;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import com.lkx.liandianqinew.R;

public abstract class AttachBottomPopupView extends BasePopupView {
    protected FrameLayout attachPopupContainer = ((FrameLayout) findViewById(R.id.attachPopupContainer));
    float centerY = 0.0f;
    protected int defaultOffsetX = 0;
    protected int defaultOffsetY = 0;
    public boolean isShowLeft;
    public boolean isShowUp;
    float maxY = ((float) XPopupUtils.getAppHeight(getContext()));
    int overflow = XPopupUtils.dp2px(getContext(), 10.0f);
    float translationX = 0.0f;
    float translationY = 0.0f;

    public AttachBottomPopupView(Context context) {
        super(context);
    }

    /* access modifiers changed from: protected */
    public void addInnerContent() {
        this.attachPopupContainer.addView(LayoutInflater.from(getContext()).inflate(getImplLayoutId(), (ViewGroup) this.attachPopupContainer, false));
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public final int getInnerLayoutId() {
        return R.layout._xpopup_attach_popup_view_bottom;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void initPopupContent() {
        super.initPopupContent();
        if (this.attachPopupContainer.getChildCount() == 0) {
            addInnerContent();
        }
        if (this.popupInfo.atView == null && this.popupInfo.touchPoint == null) {
            throw new IllegalArgumentException("atView() or watchView() must be called for AttachPopupView before show()！");
        }
        this.defaultOffsetY = this.popupInfo.offsetY;
        this.defaultOffsetX = this.popupInfo.offsetX;
        this.attachPopupContainer.setTranslationX((float) this.popupInfo.offsetX);
        this.attachPopupContainer.setTranslationY((float) this.popupInfo.offsetY);
        applyBg();
        XPopupUtils.applyPopupSize((ViewGroup) getPopupContentView(), getMaxWidth(), getMaxHeight(), getPopupWidth(), getPopupHeight(), new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.AttachBottomPopupView.AnonymousClass1 */

            public void run() {
                AttachBottomPopupView.this.doAttach();
            }
        });
    }

    /* access modifiers changed from: protected */
    public void applyBg() {
        Drawable.ConstantState constantState;
        Drawable.ConstantState constantState2;
        if (this.isCreated) {
            return;
        }
        if (Build.VERSION.SDK_INT >= 21) {
            if (!(getPopupImplView().getBackground() == null || (constantState2 = getPopupImplView().getBackground().getConstantState()) == null)) {
                this.attachPopupContainer.setBackground(constantState2.newDrawable(getResources()));
                getPopupImplView().setBackground(null);
            }
            this.attachPopupContainer.setElevation((float) XPopupUtils.dp2px(getContext(), 20.0f));
        } else if (getPopupImplView().getBackground() != null && (constantState = getPopupImplView().getBackground().getConstantState()) != null) {
            this.attachPopupContainer.setBackground(constantState.newDrawable(getResources()));
            getPopupImplView().setBackground(null);
        }
    }

    public void doAttach() {
        int i;
        float f;
        if (this.popupInfo != null) {
            boolean z = false;
            int navBarHeight = XPopupUtils.isNavBarVisible(getHostWindow()) ? XPopupUtils.getNavBarHeight() : 0;
            this.maxY = (float) ((XPopupUtils.getAppHeight(getContext()) - this.overflow) - navBarHeight);
            final boolean isLayoutRtl = XPopupUtils.isLayoutRtl(getContext());
            if (this.popupInfo.touchPoint != null) {
                if (XPopup.longClickPoint != null) {
                    this.popupInfo.touchPoint = XPopup.longClickPoint;
                }
                this.centerY = this.popupInfo.touchPoint.y;
                if (this.popupInfo.touchPoint.y + ((float) getPopupContentView().getMeasuredHeight()) > this.maxY) {
                    this.isShowUp = this.popupInfo.touchPoint.y > ((float) (XPopupUtils.getScreenHeight(getContext()) / 2));
                } else {
                    this.isShowUp = false;
                }
                if (this.popupInfo.touchPoint.x < ((float) (XPopupUtils.getAppWidth(getContext()) / 2))) {
                    z = true;
                }
                this.isShowLeft = z;
                ViewGroup.LayoutParams layoutParams = getPopupContentView().getLayoutParams();
                if (isShowUpToTarget()) {
                    f = (this.popupInfo.touchPoint.y - ((float) XPopupUtils.getStatusBarHeight())) - ((float) this.overflow);
                } else {
                    f = ((((float) XPopupUtils.getScreenHeight(getContext())) - this.popupInfo.touchPoint.y) - ((float) this.overflow)) - ((float) navBarHeight);
                }
                int i2 = (int) f;
                int appWidth = (int) ((this.isShowLeft ? ((float) XPopupUtils.getAppWidth(getContext())) - this.popupInfo.touchPoint.x : this.popupInfo.touchPoint.x) - ((float) this.overflow));
                if (getPopupContentView().getMeasuredHeight() > i2) {
                    layoutParams.height = i2;
                }
                if (getPopupContentView().getMeasuredWidth() > appWidth) {
                    layoutParams.width = Math.max(appWidth, getPopupWidth());
                }
                getPopupContentView().setLayoutParams(layoutParams);
                getPopupContentView().post(new Runnable() {
                    /* class com.youyi.yyviewsdklibrary.Dialog.core.AttachBottomPopupView.AnonymousClass2 */

                    public void run() {
                        float f;
                        if (AttachBottomPopupView.this.popupInfo != null) {
                            if (isLayoutRtl) {
                                AttachBottomPopupView attachBottomPopupView = AttachBottomPopupView.this;
                                if (attachBottomPopupView.isShowLeft) {
                                    f = ((((float) XPopupUtils.getAppWidth(AttachBottomPopupView.this.getContext())) - AttachBottomPopupView.this.popupInfo.touchPoint.x) - ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) - ((float) AttachBottomPopupView.this.defaultOffsetX);
                                } else {
                                    f = (((float) XPopupUtils.getAppWidth(AttachBottomPopupView.this.getContext())) - AttachBottomPopupView.this.popupInfo.touchPoint.x) + ((float) AttachBottomPopupView.this.defaultOffsetX);
                                }
                                attachBottomPopupView.translationX = -f;
                            } else {
                                AttachBottomPopupView attachBottomPopupView2 = AttachBottomPopupView.this;
                                attachBottomPopupView2.translationX = attachBottomPopupView2.isShowLeft ? AttachBottomPopupView.this.popupInfo.touchPoint.x + ((float) AttachBottomPopupView.this.defaultOffsetX) : (AttachBottomPopupView.this.popupInfo.touchPoint.x - ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) - ((float) AttachBottomPopupView.this.defaultOffsetX);
                            }
                            if (AttachBottomPopupView.this.popupInfo.isCenterHorizontal) {
                                if (AttachBottomPopupView.this.isShowLeft) {
                                    if (isLayoutRtl) {
                                        AttachBottomPopupView.this.translationX += ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                                    } else {
                                        AttachBottomPopupView.this.translationX -= ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                                    }
                                } else if (isLayoutRtl) {
                                    AttachBottomPopupView.this.translationX -= ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                                } else {
                                    AttachBottomPopupView.this.translationX += ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                                }
                            }
                            if (AttachBottomPopupView.this.isShowUpToTarget()) {
                                AttachBottomPopupView attachBottomPopupView3 = AttachBottomPopupView.this;
                                attachBottomPopupView3.translationY = (attachBottomPopupView3.popupInfo.touchPoint.y - ((float) AttachBottomPopupView.this.getPopupContentView().getMeasuredHeight())) - ((float) AttachBottomPopupView.this.defaultOffsetY);
                            } else {
                                AttachBottomPopupView attachBottomPopupView4 = AttachBottomPopupView.this;
                                attachBottomPopupView4.translationY = attachBottomPopupView4.popupInfo.touchPoint.y + ((float) AttachBottomPopupView.this.defaultOffsetY);
                            }
                            AttachBottomPopupView.this.translationX -= (float) AttachBottomPopupView.this.getActivityContentLeft();
                            AttachBottomPopupView.this.getPopupContentView().setTranslationX(AttachBottomPopupView.this.translationX);
                            AttachBottomPopupView.this.getPopupContentView().setTranslationY(AttachBottomPopupView.this.translationY);
                            AttachBottomPopupView.this.initAndStartAnimation();
                        }
                    }
                });
                return;
            }
            final Rect atViewRect = this.popupInfo.getAtViewRect();
            int i3 = (atViewRect.left + atViewRect.right) / 2;
            boolean z2 = ((float) (atViewRect.bottom + getPopupContentView().getMeasuredHeight())) > this.maxY;
            this.centerY = (float) ((atViewRect.top + atViewRect.bottom) / 2);
            if (z2) {
                int statusBarHeight = (atViewRect.top - XPopupUtils.getStatusBarHeight()) - this.overflow;
                if (getPopupContentView().getMeasuredHeight() > statusBarHeight) {
                    this.isShowUp = ((float) statusBarHeight) > this.maxY - ((float) atViewRect.bottom);
                } else {
                    this.isShowUp = true;
                }
            } else {
                this.isShowUp = false;
            }
            if (i3 < XPopupUtils.getAppWidth(getContext()) / 2) {
                z = true;
            }
            this.isShowLeft = z;
            ViewGroup.LayoutParams layoutParams2 = getPopupContentView().getLayoutParams();
            if (isShowUpToTarget()) {
                i = (atViewRect.top - XPopupUtils.getStatusBarHeight()) - this.overflow;
            } else {
                i = ((XPopupUtils.getScreenHeight(getContext()) - atViewRect.bottom) - this.overflow) - navBarHeight;
            }
            int appWidth2 = (this.isShowLeft ? XPopupUtils.getAppWidth(getContext()) - atViewRect.left : atViewRect.right) - this.overflow;
            if (getPopupContentView().getMeasuredHeight() > i) {
                layoutParams2.height = i;
            }
            if (getPopupContentView().getMeasuredWidth() > appWidth2) {
                layoutParams2.width = Math.max(appWidth2, getPopupWidth());
            }
            getPopupContentView().setLayoutParams(layoutParams2);
            getPopupContentView().post(new Runnable() {
                /* class com.youyi.yyviewsdklibrary.Dialog.core.AttachBottomPopupView.AnonymousClass3 */

                public void run() {
                    int i;
                    if (AttachBottomPopupView.this.popupInfo != null) {
                        if (isLayoutRtl) {
                            AttachBottomPopupView attachBottomPopupView = AttachBottomPopupView.this;
                            if (attachBottomPopupView.isShowLeft) {
                                i = ((XPopupUtils.getAppWidth(AttachBottomPopupView.this.getContext()) - atViewRect.left) - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) - AttachBottomPopupView.this.defaultOffsetX;
                            } else {
                                i = (XPopupUtils.getAppWidth(AttachBottomPopupView.this.getContext()) - atViewRect.right) + AttachBottomPopupView.this.defaultOffsetX;
                            }
                            attachBottomPopupView.translationX = (float) (-i);
                        } else {
                            AttachBottomPopupView attachBottomPopupView2 = AttachBottomPopupView.this;
                            attachBottomPopupView2.translationX = (float) (attachBottomPopupView2.isShowLeft ? atViewRect.left + AttachBottomPopupView.this.defaultOffsetX : (atViewRect.right - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth()) - AttachBottomPopupView.this.defaultOffsetX);
                        }
                        if (AttachBottomPopupView.this.popupInfo.isCenterHorizontal) {
                            if (AttachBottomPopupView.this.isShowLeft) {
                                if (isLayoutRtl) {
                                    AttachBottomPopupView.this.translationX -= ((float) (atViewRect.width() - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                                } else {
                                    AttachBottomPopupView.this.translationX += ((float) (atViewRect.width() - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                                }
                            } else if (isLayoutRtl) {
                                AttachBottomPopupView.this.translationX += ((float) (atViewRect.width() - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                            } else {
                                AttachBottomPopupView.this.translationX -= ((float) (atViewRect.width() - AttachBottomPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                            }
                        }
                        if (AttachBottomPopupView.this.isShowUpToTarget()) {
                            AttachBottomPopupView.this.translationY = (float) ((atViewRect.top - AttachBottomPopupView.this.getPopupContentView().getMeasuredHeight()) - AttachBottomPopupView.this.defaultOffsetY);
                        } else {
                            AttachBottomPopupView.this.translationY = (float) (atViewRect.bottom + AttachBottomPopupView.this.defaultOffsetY);
                        }
                        AttachBottomPopupView.this.translationX -= (float) AttachBottomPopupView.this.getActivityContentLeft();
                        AttachBottomPopupView.this.getPopupContentView().setTranslationX(AttachBottomPopupView.this.translationX);
                        AttachBottomPopupView.this.getPopupContentView().setTranslationY(AttachBottomPopupView.this.translationY);
                        AttachBottomPopupView.this.initAndStartAnimation();
                    }
                }
            });
        }
    }

    /* access modifiers changed from: protected */
    public void initAndStartAnimation() {
        initAnimator();
        doShowAnimation();
        doAfterShow();
    }

    /* access modifiers changed from: protected */
    public boolean isShowUpToTarget() {
        if (this.popupInfo.positionByWindowCenter) {
            if (this.centerY > ((float) (XPopupUtils.getAppHeight(getContext()) / 2))) {
                return true;
            }
            return false;
        } else if ((this.isShowUp || this.popupInfo.popupPosition == PopupPosition.Top) && this.popupInfo.popupPosition != PopupPosition.Bottom) {
            return true;
        } else {
            return false;
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public PopupAnimator getPopupAnimator() {
        ScrollScaleAnimator scrollScaleAnimator;
        PopupAnimation popupAnimation;
        PopupAnimation popupAnimation2;
        if (isShowUpToTarget()) {
            View popupContentView = getPopupContentView();
            int animationDuration = getAnimationDuration();
            if (this.isShowLeft) {
                popupAnimation2 = PopupAnimation.ScrollAlphaFromLeftBottom;
            } else {
                popupAnimation2 = PopupAnimation.ScrollAlphaFromRightBottom;
            }
            scrollScaleAnimator = new ScrollScaleAnimator(popupContentView, animationDuration, popupAnimation2);
        } else {
            View popupContentView2 = getPopupContentView();
            int animationDuration2 = getAnimationDuration();
            if (this.isShowLeft) {
                popupAnimation = PopupAnimation.ScrollAlphaFromLeftTop;
            } else {
                popupAnimation = PopupAnimation.ScrollAlphaFromRightTop;
            }
            scrollScaleAnimator = new ScrollScaleAnimator(popupContentView2, animationDuration2, popupAnimation);
        }
        return scrollScaleAnimator;
    }
}
